On a rectangular mesh comprising
fields,
cuboids were put, one cuboid on each field. A base of each cuboid covers one field and its surface equals to one square inch. Cuboids on adjacent fields adhere one to another so close that there are no gaps between them. A heavy rain pelted on a construction so that in some areas puddles of water appeared.
Write a program which:
In the first line of the standard input two positive integers
and
,
,
are written. They are the size of the mesh. In each of the following
lines there are
integers from the interval
;
-th number in
-th line denotes a height of a cuboid given in inches put on the field in the
-th column and
-th raw of the chessboard.
Your program should write in the first and the only line of the standard output one integer equal to the maximal volume of water (given in cubic inches), which may gather in puddles on the construction.
For the input data:
3 6 3 3 4 4 4 2 3 1 3 2 1 4 7 3 1 6 4 1
the correct result is:
5
A picture below shows the mesh after the rain (seen from above). Puddles are drawn in gray.

Task author: Grzegorz Jakacki.
In the event of technical difficulties with Szkopuł, please contact us via email at [email protected].
If you would like to talk about tasks, solutions or technical problems, please visit our Discord servers. They are moderated by the community, but members of the support team are also active there.